import { getAction, deleteAction, postAction } from '@/api/manage'
import { serviceApi } from '@/api/common.js'
/**
 * 公共API接口
 */
export const api = {
  list: (projectId, params) => serviceApi.auth + `/users/projects/${projectId}`,
  delete: (userId, projectId) => serviceApi.auth + `/users/${userId}/projects/${projectId}/delete`,
  deleteBatch: (projectId) => serviceApi.auth + `/users/projects/${projectId}/delete-batch`
}

/**
* 获取用户角色列表
* @param {*} params
* @returns
*/
export const getUserProjectList = (projectId, params) => getAction(api.list(projectId, params), params)

/**
 * 添加用户项目
 * @param params
 * @returns {*}
 */
export const addUserProject = (projectId, params) => postAction(serviceApi.auth + `/users/projects/${projectId}/add-user`, params);

/**
 * 添加已有用户的项目关系
 * @param projectId
 * @param params
 * @returns {AxiosPromise}
 */
export const addExistUser = (projectId, params) => postAction(serviceApi.auth + `/users/projects/${projectId}/add-exist-users`, params);

/**
 * 删除用户角色
 * @param params
 * @returns {AxiosPromise}
 */
export const deleteUserRole = (userId, roleId, params) => deleteAction(api.delete(userId, roleId), params);

/**
 * 批量删除用户角色
 * @param params
 * @returns {AxiosPromise}
 */
export const batchDeleteUserRole = (userId, roleId, params) => deleteAction(api.delete(userId, roleId), params);
